var a, t = require("../../../@babel/runtime/helpers/interopRequireDefault"), e = t(require("../../../@babel/runtime/regenerator")), i = require("../../../@babel/runtime/helpers/defineProperty"), s = require("../../../@babel/runtime/helpers/toConsumableArray"), r = require("../../../@babel/runtime/helpers/asyncToGenerator"), n = t(require("../../../utils/api")), u = getApp();

Page({
    data: {
        windowHeight: u.globalData.windowHeight,
        tip: "下拉刷新更多内容",
        pageNum: 1,
        pageSize: 9,
        list: [],
        myData: {},
        more: !0,
        tabs: [],
        activeTab: 0,
        tabSwiperHeight: 0
    },
    tabsSwiperHeight: function() {
        var a = this.data.activeTab, t = (this.data.tabs[a].list, this.data.tabs[a].myData ? 195 : 0), e = 170 * this.data.tabs[a].list.length;
        this.setData({
            tabSwiperHeight: t + e + 130 > 2 * (this.data.windowHeight - 56) ? t + e + 130 : 2 * (this.data.windowHeight - 56)
        });
    },
    getList: function() {
        var a = this;
        return r(e.default.mark(function t() {
            var r, u, b, l, c, d, p, o, h;
            return e.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    if (r = wx.getStorageSync("openid"), t.prev = 1, b = null, 0 != a.data.activeTab && 1 != a.data.activeTab) {
                        t.next = 9;
                        break;
                    }
                    return t.next = 6, n.default.rankRecord({
                        openid: r,
                        lastMonth: a.data.tabs[a.data.activeTab].lastMonth,
                        pageNum: a.data.tabs[a.data.activeTab].pageNum,
                        pageSize: a.data.tabs[a.data.activeTab].pageSize
                    });

                  case 6:
                    b = t.sent, t.next = 12;
                    break;

                  case 9:
                    return t.next = 11, n.default.activityRank({
                        openid: r,
                        activityId: a.data.tabs[a.data.activeTab].id,
                        pageNum: a.data.tabs[a.data.activeTab].pageNum,
                        pageSize: a.data.tabs[a.data.activeTab].pageSize
                    });

                  case 11:
                    b = t.sent;

                  case 12:
                    (l = a.data.tabs[a.data.activeTab].list).push.apply(l, s(b.result.list)), c = "tabs[" + a.data.activeTab + "].list", 
                    d = "tabs[" + a.data.activeTab + "].myData", a.setData((i(u = {}, c, l), i(u, d, b.result.myData), 
                    u)), a.tabsSwiperHeight(), p = "tabs[" + a.data.activeTab + "].more", o = "tabs[" + a.data.activeTab + "].tip", 
                    b.result.list.length < a.data.tabs[a.data.activeTab].pageSize && a.setData((i(h = {}, p, !1), 
                    i(h, o, "没有更多了"), h)), t.next = 26;
                    break;

                  case 23:
                    t.prev = 23, t.t0 = t.catch(1), console.log(t.t0.msg);

                  case 26:
                  case "end":
                    return t.stop();
                }
            }, t, null, [ [ 1, 23 ] ]);
        }))();
    },
    onLoad: (a = r(e.default.mark(function a(t) {
        var i, s;
        return e.default.wrap(function(a) {
            for (;;) switch (a.prev = a.next) {
              case 0:
                return i = [ {
                    title: "本月排名",
                    lastMonth: 0,
                    tip: "下拉刷新更多内容",
                    pageNum: 1,
                    pageSize: 8,
                    list: [],
                    myData: null,
                    more: !0
                }, {
                    title: "上月排名",
                    lastMonth: 1,
                    tip: "下拉刷新更多内容",
                    pageNum: 1,
                    pageSize: 8,
                    list: [],
                    myData: null,
                    more: !0
                } ], s = wx.getStorageSync("openid"), a.prev = 2, a.next = 5, n.default.activityList({
                    openid: s
                });

              case 5:
                a.sent.result.list.forEach(function(a) {
                    i.push({
                        id: a.id,
                        title: a.name,
                        tip: "下拉刷新更多内容",
                        pageNum: 1,
                        pageSize: 8,
                        list: [],
                        myData: null,
                        more: !0
                    });
                }), this.setData({
                    tabs: i,
                    activeTab: 0
                }), a.next = 13;
                break;

              case 10:
                a.prev = 10, a.t0 = a.catch(2), console.log(a.t0);

              case 13:
                this.getList();

              case 14:
              case "end":
                return a.stop();
            }
        }, a, this, [ [ 2, 10 ] ]);
    })), function(t) {
        return a.apply(this, arguments);
    }),
    onReachBottom: function() {
        var a = this.data.activeTab, t = "tabs[" + this.data.activeTab + "].pageNum";
        this.data.tabs[a].more && (this.setData(i({}, t, ++this.data.tabs[a].pageNum)), 
        this.getList());
    },
    onChange: function(a) {
        var t, e = a.detail.index, s = "tabs[" + e + "].list", r = "tabs[" + e + "].pageNum";
        this.setData((i(t = {
            activeTab: e
        }, s, []), i(t, r, 1), i(t, "tabSwiperHeight", 0), t)), this.getList();
    }
});